package cn.it.utils;

import cn.it.anno.MyAutowired;
import cn.it.anno.MyComponent;

import java.sql.SQLException;

@MyComponent
public class TransactionManager {

    @MyAutowired
    private ConnectionUtils connectionUtils;

    public void setConnectionUtils(ConnectionUtils connectionUtils) {
        this.connectionUtils = connectionUtils;
    }

    public void begin() throws SQLException {
        connectionUtils.getCurrentConn().setAutoCommit(false);
    }

    public void commit() throws SQLException {
        connectionUtils.getCurrentConn().commit();
    }

    public void rollback() throws SQLException {
        connectionUtils.getCurrentConn().rollback();
    }
}
